<!DOCTYPE html>
<html lang="en" style="background:#fff;">
<head>
    <base href="${basePath}">
    <#include "common/top.html"/>
    <link type="text/css" rel="stylesheet" href="${basePath}plugins/zTree/3.5.1/zTreeStyle/zTreeStyle.css"/>
    <script type="text/javascript" src="${basePath}plugins/zTree/3.5.1/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="${basePath}plugins/zTree/3.5.1/jquery.ztree.excheck.js"></script>
    <style>
        .layui-input, .layui-textarea, .layui-form-select dl {
            width: 260px;
        }

        .layui-form-label span {
            display: block;
            float: left;
            width: 8px;
            height: 5px;
        }

        .layui-form-label {
            width: 115px;
        }
    </style>
</head>
<body style="background:#fff;">
<form class="layui-form" modelAttribute="emp" name="form1" id="form1" method="post" style="margin: 0 auto; width: 90%;"
      action="">
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red;">*</span>员工编号：</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="comUserCode" maxlength="30" id="comUserCode"
                   placeholder="请输入企业员工编号"
                   value="${comEmp.comUserCode}" title="员工编号"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red;">*</span>员工名称：</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="comUserName" id="comUserName" placeholder="请输入企业员工名称"
                   value="${comEmp.comUserName}" title="员工名称"/>
        </div>
    </div>
    <#if roleId == '1'>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red;">*</span>企业名称:</label>
            <div class="layui-input-inline">
                <select id="comCode" name="comCode" lay-filter="comCode" lay-verify="" lay-search>
                    <option value="">--请选择--</option>
                    <#list comInfoList?if_exists as comInfo >
                        <option value="${comInfo.comCode}">${comInfo.comName}</option>
                    </#list>
                </select>
            </div>
        </div>
     <#else>
         <input  type="hidden" name="comCode" id="comCode" value="${comEmp.comCode}" />
    </#if>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red;"></span>部门名称：</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="deptName" readonly id="deptName" placeholder="请选择部门"
                   value="${comEmp.deptName}" title="本级部门名称"/>
            <input class="layui-input" type="hidden" name="deptCode" readonly id="deptCode" placeholder="请选择部门"
                   value="${comEmp.deptCode}" title="本级部门编号"/>
            <div id="parentDiv" class="layui-elem-field" style="width:258px;height: 200px;overflow: auto;">
                <ul id="tree" class="ztree" style="padding: 5px;"></ul>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red;"></span>职位名称：</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="postName" id="postName" placeholder="请输入职位名称"
                   value="${comEmp.postName}" title="职位名称"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red;"> </span>座机号：</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="contactTel" id="contactTel" placeholder="请输入座机号"
                   value="${comEmp.contactTel}" title="座机号"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red;">*</span>手机号码：</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="contactMobile" id="contactMobile" placeholder="请输入联系人手机号"
                   value="${comEmp.contactMobile}" title="联系人手机号"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red;"> </span>邮箱：</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="comEmail" id="comEmail" placeholder="请输入联系人邮箱"
                   value="${comEmp.comEmail}" title="联系人邮箱"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red;">*</span>证件类型:</label>
        <div class="layui-input-inline">
            <select id="idType" name="idType" lay-filter="idType">
                <option value="">--请选择--</option>
                <option value="I">身份证</option>
                <option value="S">军官证</option>
                <option value="E">通行证</option>
                <option value="H">护照</option>
            </select>
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red;">*</span>证件号码：</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="idNo" id="idNo" placeholder="请输入证件号码" value="${comEmp.idNo}"
                   title="证件号码"/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red;">*</span>地址：</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="address" id="address" placeholder="请输入地址"
                   value="${comEmp.address}" title="地址"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red;">*</span>通讯录显示模式：</label>
        <div class="layui-input-inline">
            <select name="dispType" id="dispType" lay-verify="dispType">
                <option value="">--请选择--</option>
                <option value="0">默认模式</option>
                <option value="1">手机号码隐藏模式</option>
                <option value="2">手机和座机号码隐藏模式</option>
            </select>
        </div>
    </div>
   <!-- <div class="layui-form-item">
        <label class="layui-form-label"><span style="color: red;">*</span>可见属性：</label>
        <div class="layui-input-inline">
            <select name="visible" id="visible" lay-verify="visible">
                <option value="">&#45;&#45;请选择&#45;&#45;</option>
                <option value="0">全部可见</option>
                <option value="1">下级不可见</option>
                <option value="2">全部不可见</option>
            </select>
        </div>
    </div>-->
</form>
</body>
<script type="text/javascript">
    var zTree;
    $(document).ready(function () {
        $("#parentDiv").hide();
        $("#deptName").click(function (event) {
            $("#parentDiv").show();
            event.stopPropagation();//阻止冒泡
        });
        $("body").click(function () {
            $("#parentDiv").hide();
        })
        $('#parentDiv').click(function () {
            return false;
        });
        var zn = '${zTreeNodes}';
        zn=zn.replace(/&quot;/g,'"');//转换后台返回的&quot;
        var setting = {
            data: {
                key: {
                    title: "dept"
                },
                simpleData: {
                    enable: true,
                    idKey: "id",
                    pIdKey: "pId",
                    rootPId: 0
                }
            },
            callback: {
                onClick: zTreeOnClick
            }
        };
        var zNodes = eval(zn);
        zTree = $.fn.zTree.init($("#tree"), setting, zNodes);
    });

    function zTreeOnClick(event, treeId, treeNode) {
        $("#deptCode").val(treeNode.id);
        $("#deptName").val(treeNode.name);
        $("#parentDiv").hide();
    }

    var $form;
    var form;
    var rooturl = '${basePath}sysuser/user/toUserEdit';
    layui.use(['form', 'layedit', 'laydate'], function () {
        form = layui.form();
        $("#comCode option").each(function () {
            if ($(this).val() == "${comEmp.comCode}") {
                $(this).attr("selected", true);
            }
        });
        $("#idType option").each(function () {
            if ($(this).val() == "${comEmp.idType}") {
                $(this).attr("selected", true);
            }
        });
        $form = $('form')
        $("#dispType option").each(function () {
            if ($(this).val() == "${comEmp.dispType}") {
                $(this).attr("selected", true);
            }
        });
    /*    $form = $('form')
        $("#visible option").each(function () {
            if ($(this).val() == "${comEmp.visible}") {
                $(this).attr("selected", true);
            }
        });*/
        form.render();
    });

    function goto() {
        _GLOBE_DATA("reLoadPageParam")(_GLOBE_DATA("createURL")(rooturl, "searchbox"));
    }


    var zTree;
    $(document).ready(function () {
        if ($("#comUserCode").val() != "") {
            $("#comUserCode").attr("readonly", "readonly").css("color", "gray");
            ;
            /*	$("#deptName").attr("disabled",false).css("color","gray");
             $("#postName").attr("readonly","readonly").css("color","gray");
             $("#comUserName").css("color","gray");*/
        }

    });

    //保存
    function save() {
        if (
            checkIsNull("comUserCode", "请输入用户编号！") ||
            checkIsNull("comUserName", "请输入员工姓名！")
        ) {
            return;
        }
        ;
        if ("1" == '${roleId}') {
            //判断企业名称
            if ($("#comCode").val() == "" || $("#comCode").val() == null) {
                $("#comCode_1").tips({
                    side: 2,
                    msg: '请选择企业类型',
                    bg: '#fe5d6f',
                    time: 2
                });
                $("#comCode_1").focus();
                return
            }
            ;
        }

        if (checkMob("contactMobile")) {
            return;
        }
        ;


        //判断邮箱
        var rep = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
        if ($("#comEmail").val() != "" && $("#comEmail").val() != null) {
            if (!(rep.test($("#comEmail").val()))) {
                $("#comEmail").tips({
                    side: 3,
                    msg: '邮箱输入有误',
                    bg: '#fe5d6f',
                    time: 2
                });
                $("#comEmail").focus();
                return false;
            }
        }


        //判断证件类型
        if ($("#idType").val() == "" || $("#idType").val() == null) {
            $("#idType_1").tips({
                side: 2,
                msg: '请选择证件类型',
                bg: '#fe5d6f',
                time: 2
            });
            $("#idType_1").focus();
            return
        }
        ;
        if (checkIsNull("idNo", "请输入身份证号码！")) {
            return;
        }
        ;
        //判断身份证号
        if ($("#idType").val() == "I") {
            var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
            if ($("#idNo").val() != "" && $("#idNo").val() != null) {
                if (!(reg.test($("#idNo").val()))) {
                    $("#idNo").tips({
                        side: 2,
                        msg: '证件号输入有误',
                        bg: '#fe5d6f',
                        time: 2
                    });
                    $("#idNo").focus();
                    return false;
                }
            } else {
                $("#idNo").tips({
                    side: 2,
                    msg: '不能为空',
                    bg: '#fe5d6f',
                    time: 2
                });
                $("#idNo").focus();
                return false;
            }
        }
        //护照
        if ($("#idType").val() == "H") {
            debugger;
            if ($("#idNo").val().length > 9) {
                $("#idNo").tips({
                    side: 2,
                    msg: '证件编号不能大于9位数',
                    bg: '#fe5d6f',
                    time: 2
                });
                $("#idNo").focus();
                return false;
            }
        }
        ;
        //军官证
        if ($("#idType").val() == "S") {
            debugger;
            if ($("#idNo").val().length > 9) {
                $("#idNo").tips({
                    side: 2,
                    msg: '证件编号不能大于8位数',
                    bg: '#fe5d6f',
                    time: 2
                });
                $("#idNo").focus();
                return false;
            }
        }
        ;
        //通行证
        if ($("#idType").val() == "E") {
            debugger;
            if ($("#idNo").val().length > 9) {
                $("#idNo").tips({
                    side: 2,
                    msg: '证件编号不能大于8位数',
                    bg: '#fe5d6f',
                    time: 2
                });
                $("#idNo").focus();
                return false;
            }
        }
        ;


        if ($("#comUserCode").val() == "" && $("#userPassword").val() == "") {
            $("#userPassword").tips({
                side: 3,
                msg: '输入密码',
                bg: '#fe5d6f',
                time: 2
            });
            $("#userPassword").focus();
            return false;
        }
        ;
        if (
            checkIsNull("address", "请输入地址！")
        ) {
            return;
        }
        ;
        //判断通讯录显示模式
        if ($("#dispType").val() == "" || $("#dispType").val() == null) {
            $("#dispType_1").tips({
                side: 2,
                msg: '请选择通讯录显示模式',
                bg: '#fe5d6f',
                time: 2
            });
            $("#dispType_1").focus();
            return
        };
       /* //可见属性选择
        if ($("#visible").val() == "" || $("#visible").val() == null) {
            $("#visible_1").tips({
                side: 2,
                msg: '请选择通讯录显示模式',
                bg: '#fe5d6f',
                time: 2
            });
            $("#visible_1").focus();
            return
        };*/

        $.ajax({
            url: '${basePath}/sysuser/user/save.do',
            data: $("#form1").serialize(),
            type: "POST",
            success: function (data) {
                if (data.status == 'success') {
                    parent.layer.alert(data.msg, function (index) {
                        var index1 = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index1);
                        parent.layer.close(index);
                    });
                } else {
                    parent.layer.alert(data.msg);
                }
            }
        });
    }

    //修改
    function update() {

        if (
            checkIsNull("comUserCode", "请输入用户编号！") ||
            checkIsNull("comUserName", "请输入员工姓名！")
        ) {
            return;
        }
        ;

        //判断企业名称
        if ("1" == '${roleId}') {
            if ($("#comCode").val() == "" || $("#comCode").val() == null) {
                $("#comCode_1").tips({
                    side: 2,
                    msg: '请选择企业类型',
                    bg: '#fe5d6f',
                    time: 2
                });
                $("#comCode_1").focus();
                return
            }
            ;
        }
        if (checkMob("contactMobile")) {
            return;
        }
        ;


        //判断邮箱
        var rep = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
        if ($("#comEmail").val() != "" && $("#comEmail").val() != null) {
            if (!(rep.test($("#comEmail").val()))) {
                $("#comEmail").tips({
                    side: 3,
                    msg: '邮箱输入有误',
                    bg: '#fe5d6f',
                    time: 2
                });
                $("#comEmail").focus();
                return false;
            }
        }


        //判断证件类型
        if ($("#idType").val() == "" || $("#idType").val() == null) {
            $("#idType_1").tips({
                side: 2,
                msg: '请选择证件类型',
                bg: '#fe5d6f',
                time: 2
            });
            $("#idType_1").focus();
            return
        }
        ;
        if (checkIsNull("idNo", "请输入身份证号码！")) {

        }
        ;
        //判断身份证号
        if ($("idType").val() == "I") {
            var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
            if ($("#idNo").val() != "" && $("#idNo").val() != null) {
                if (!(reg.test($("#idNo").val()))) {
                    $("#idNo").tips({
                        side: 2,
                        msg: '身份证输入有误',
                        bg: '#fe5d6f',
                        time: 2
                    });
                    $("#idNo").focus();
                    return false;
                }
            } else {
                $("#idNo").tips({
                    side: 2,
                    msg: '不能为空',
                    bg: '#fe5d6f',
                    time: 2
                });
                $("#idNo").focus();
                return false;
            }
        }
        //护照
        if ($("#idType").val() == "H") {
            debugger;
            if ($("#idNo").val().length > 9) {
                $("#idNo").tips({
                    side: 2,
                    msg: '证件编号不能大于9位数',
                    bg: '#fe5d6f',
                    time: 2
                });
                $("#idNo").focus();
                return false;
            }
        }
        ;
        //军官证
        if ($("#idType").val() == "S") {
            debugger;
            if ($("#idNo").val().length > 9) {

                $("#idNo").tips({
                    side: 2,
                    msg: '证件编号不能大于8位数',
                    bg: '#fe5d6f',
                    time: 2
                });
                $("#idNo").focus();
                return false;
            }
        }
        ;
        //通行证
        if ($("#idType").val() == "E") {
            debugger;
            if ($("#idNo").val().length > 9) {

                $("#idNo").tips({
                    side: 2,
                    msg: '证件编号不能大于8位数',
                    bg: '#fe5d6f',
                    time: 2
                });
                $("#idNo").focus();
                return false;
            }
        }
        ;


        if ($("#comUserCode").val() == "" && $("#userPassword").val() == "") {
            $("#userPassword").tips({
                side: 3,
                msg: '输入密码',
                bg: '#fe5d6f',
                time: 2
            });
            $("#userPassword").focus();
            return false;
        }
        ;
        /*if (
            checkIsNull("address", "请输入地址！") ||
            checkIsNull("deptName", "请输入本级部门名称！")
        ) {
            return;
        }
        ;*/
        //判断通讯录显示模式
        if ($("#dispType").val() == "" || $("#dispType").val() == null) {
            $("#dispType_1").tips({
                side: 2,
                msg: '请选择通讯录显示模式',
                bg: '#fe5d6f',
                time: 2
            });
            $("#dispType_1").focus();
            return
        };
       /* //可见属性选择
        if ($("#visible").val() == "" || $("#visible").val() == null) {
            $("#visible_1").tips({
                side: 2,
                msg: '请选择通讯录显示模式',
                bg: '#fe5d6f',
                time: 2
            });
            $("#visible_1").focus();
            return
        };
*/



        $.ajax({
            url: '${basePath}/sysuser/user/Update.do',
            data: $("#form1").serialize(),
            type: "POST",
            success: function (data) {
                if (data.status == 'success') {
                    parent.layer.alert(data.msg, function (index) {
                        var index1 = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index1);
                        parent.layer.close(index);
                    });
                } else {
                    parent.layer.alert(data.msg);
                }
            }
        });
    }
</script>
</body>
</html>